﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using System.Reflection;

namespace KitBuilder.DataAccess
{
    class NHADO
    {
        private static ISessionFactory sessionFactory = null;

        private static void buildFactory(){
            if(sessionFactory == null){
                    Configuration cfg = new Configuration();
                    cfg.Configure("hibernate.cfg.xml");
                    cfg.AddAssembly(Assembly.GetCallingAssembly());
                    sessionFactory = cfg.BuildSessionFactory();
            }
        }

        public static ISessionFactory MySessionFactory
        {
            get
            {
                if(sessionFactory == null)
                {
                    buildFactory();
                }
                return sessionFactory;
            }
        }



        public static ISession OpenSession()
        {
            if (sessionFactory == null)
            {
                buildFactory();
            }
            return sessionFactory.OpenSession();
        }
    }
}
